package  org.fantasy.cpp.core.pojo;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Table;

import  org.fantasy.cpp.core.annotation.Field;
import  org.fantasy.common.db.pool.DBOptions;

/**
 * 数据源
 * 
 * @author 王文成
 * @version 1.0
 * @since 2011-7-5
 */
@Table("SOURCE_INFO")
public class SourceInfo {

	@Id
	@Column("source_id")
	@Field(desc = "数据源id", nullable = false)
	private Long sourceId;

	@Column("source_type_id")
	@Field(desc = "数据源类型id", nullable = true)
	private Long sourceTypeId;

	@Column("source_name")
	@Field(desc = "数据源名称", nullable = false, maxlenth = 128)
	private String sourceName;

	@Column("source_class")
	@Field(desc = "数据源实现类", nullable = false, maxlenth = 128)
	private String sourceClass;

	@Column("url")
	@Field(desc = "数据源url", nullable = true, maxlenth = 128)
	private String url;

	@Column("user_name")
	@Field(desc = "用户名", nullable = false, maxlenth = 128)
	private String userName;

	@Column("password")
	@Field(desc = "密码", nullable = false, maxlenth = 128)
	private String password;

	@Column("driver_class")
	@Field(desc = "驱动程序", nullable = false, maxlenth = 128)
	private String driverClass;

	@Column("state")
	@Field(desc = "状态", nullable = false, maxlenth = 3)
	private String state;

	public Long getSourceId() {
		return sourceId;
	}

	public void setSourceId(Long sourceId) {
		this.sourceId = sourceId;
	}

	public Long getSourceTypeId() {
		return sourceTypeId;
	}

	public void setSourceTypeId(Long sourceTypeId) {
		this.sourceTypeId = sourceTypeId;
	}

	public String getSourceName() {
		return sourceName;
	}

	public void setSourceName(String sourceName) {
		this.sourceName = sourceName;
	}

	public String getSourceClass() {
		return sourceClass;
	}

	public void setSourceClass(String sourceClass) {
		this.sourceClass = sourceClass;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDriverClass() {
		return driverClass;
	}

	public void setDriverClass(String driverClass) {
		this.driverClass = driverClass;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	/**
	 * 转化为标准数据库配置
	 * 
	 * @return
	 */
	public DBOptions toDBOptions() {
		DBOptions options = new DBOptions();
		options.setDatabaseURL(getUrl());
		options.setDriverClassName(getDriverClass());
		options.setUser(getUserName());
		options.setPassword(getPassword());
		options.setMaxConnection(50);
		options.setMinConnection(0);
		options.setTimeout(3000);
		return options;
	}
}